/**
 * 查看二维码
 * @param selecter
 * @param content
 * @param width
 * @param height
 */
function createQrcode(selecter,content,width,height){
	var qwidth = width!=undefined?width:200;
	var qheight = height!=undefined?height:200;
	$(selecter).qrcode({ 
	    render: "canvas", //canvas,table方式 
	    width: qwidth, //宽度 
	    height:qheight, //高度 
	    text: content //任意内容 
	}); 
}

/**
 *转utf8
 */
function toUtf8(str) {    
    var out, i, len, c;    
    out = "";    
    len = str.length;    
    for(i = 0; i < len; i++) {    
        c = str.charCodeAt(i);    
        if ((c >= 0x0001) && (c <= 0x007F)) {    
            out += str.charAt(i);    
        } else if (c > 0x07FF) {    
            out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));    
            out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));    
            out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));    
        } else {    
            out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));    
            out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));    
        }    
    }    
    return out;    
}
function postData(url, parms, callback) {
	$.ajax({
		type: "POST",
		url: url,
		//async : false,
		contentType: 'application/json',
		dataType: "json",
		data: JSON.stringify(parms),
		success: callback
	});
}

function postNoAsyncData(url, parms, callback) {
	$.ajax({
		type: "POST",
		url: url,
		async : false,
		contentType: 'application/json',
		dataType: "json",
		data: JSON.stringify(parms),
		success: callback
	});
}
function refresh(){
	self.location.reload();
}
function showMesg(content,callback,icon,time){
	if(content!=undefined){
		var closetime = time!=undefined?time:3000;
		var show = icon!=undefined?icon:1;
		layer.msg(content, {
			  icon: show,
			  time: closetime //2秒关闭（如果不配置，默认是3秒）
			}, function(){
				if(callback!=undefined){
					callback();
				}
		}); 
	}
}

//对象序列化
function s(obj){
	return JSON.stringify(obj);
}
//取get参数
function getParam(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}
//深拷贝对象
//返回值:复制的新对象
function deepCopyObj(obj){
	return $.extend(true,{},obj);
}
function deepCopyArray(obj){
	return $.extend(true,[],obj);
}
//合并对象
function combine(object1,object2){
	return $.extend({}, object1, object2);
}
//刷新内容页
function refresh(){
	document.getElementById('frame').contentWindow.location.reload(true);
}
/* 
cookie相关js 
使用：$.cookie('the_cookie', 'the_value'); 
*/
(function (factory) {
	if (typeof define === 'function' && define.amd) {
		// AMD
		define(['jquery'], factory);
	} else if (typeof exports === 'object') {
		// CommonJS
		factory(require('jquery'));
	} else {
		// Browser globals
		factory(jQuery);
	}
}(function ($) {

	var pluses = /\+/g;

	function encode(s) {
		return config.raw ? s : encodeURIComponent(s);
	}

	function decode(s) {
		return config.raw ? s : decodeURIComponent(s);
	}

	function stringifyCookieValue(value) {
		return encode(config.json ? JSON.stringify(value) : String(value));
	}

	function parseCookieValue(s) {
		if (s.indexOf('"') === 0) {
			// This is a quoted cookie as according to RFC2068, unescape...
			s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
		}

		try {
			s = decodeURIComponent(s.replace(pluses, ' '));
			return config.json ? JSON.parse(s) : s;
		} catch(e) {}
	}

	function read(s, converter) {
		var value = config.raw ? s : parseCookieValue(s);
		return $.isFunction(converter) ? converter(value) : value;
	}

	var config = $.cookie = function (key, value, options) {

		// Write

		if (value !== undefined && !$.isFunction(value)) {
			options = $.extend({}, config.defaults, options);

			if (typeof options.expires === 'number') {
				var days = options.expires, t = options.expires = new Date();
				t.setTime(+t + days * 864e+5);
			}

			return (document.cookie = [
				encode(key), '=', stringifyCookieValue(value),
				options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
				options.path    ? '; path=' + options.path : '',
				options.domain  ? '; domain=' + options.domain : '',
				options.secure  ? '; secure' : ''
			].join(''));
		}

		// Read

		var result = key ? undefined : {};
		var cookies = document.cookie ? document.cookie.split('; ') : [];

		for (var i = 0, l = cookies.length; i < l; i++) {
			var parts = cookies[i].split('=');
			var name = decode(parts.shift());
			var cookie = parts.join('=');

			if (key && key === name) {
				// If second argument (value) is a function it's a converter...
				result = read(cookie, value);
				break;
			}

			// Prevent storing a cookie that we couldn't decode.
			if (!key && (cookie = read(cookie)) !== undefined) {
				result[name] = cookie;
			}
		}

		return result;
	};

	config.defaults = {};

	$.removeCookie = function (key, options) {
		if ($.cookie(key) === undefined) {
			return false;
		}

		// Must not alter options, thus extending a fresh object...
		$.cookie(key, '', $.extend({}, options, { expires: -1 }));
		return !$.cookie(key);
	};

}));